<%@ include file="/taglibs.jsp"%>
<jsp:directive.page import="java.util.Random"/>
<jsp:directive.page import="java.util.Date"/>
<%if(session.getAttribute("randFormID") == null){
	Random gen = new Random(new Date().getTime());
	session.setAttribute("randFormID", gen.nextInt() + "");
}%>


<title>Winter War Administration - Edit User</title>

<p>Please fill out your information</p>

<html:form action="/wwadmin/user" focus="user.firstName">
	<input type="hidden" name="method" value="save"/>
	<input type="hidden" name="formID" value="<%=session.getAttribute("randFormID") %>"/>
	<html:hidden property="user.userID"/>
	<input type="hidden" name="user.passwordConfirm" value="${user.password }" />
	<input type="hidden" name="where" value="admin"/>
	<table>
		<tr>
			<th><bean:message key="user.firstName"/>: </th>
			<td><html:text property="user.firstName"/></td>
			<th><bean:message key="user.phoneNumber"/>: </th>
			<td><html:text property="user.phoneNumber"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.lastName"/>: </th>
			<td><html:text property="user.lastName"/></td>
			<th><bean:message key="user.email"/>: </th>
			<td><html:text property="user.email"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.address1"/>: </th>
			<td><html:text property="user.address1"/></td>
			<th><bean:message key="user.level"/>: </th>
			<td><html:radio property="user.level" value="1">Normal</html:radio>
				<br/>
				<html:radio property="user.level" value="2">Admin</html:radio>
			</td>
		</tr>
		<tr>
			<th><bean:message key="user.address2"/>: </th>
			<td><html:text property="user.address2"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.city"/>: </th>
			<td><html:text property="user.city"/></td>
			<th><bean:message key="user.username"/>: </th>
			<td><html:text property="user.username"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.state"/>: </th>
			<td><html:text property="user.state"/></td>
			<th><bean:message key="user.password"/>: </th>
			<td><html:password property="user.password" onchange="document.forms['userForm'].elements['user.passwordConfirm'].value = this.value"/></td>
		</tr>
		<tr>
			<th><bean:message key="user.zipCode"/>: </th>
			<td><html:text property="user.zipCode"/></td>
			<th><bean:message key="user.inactive"/>: </th>
			<td><html:checkbox property="user.inactive"></html:checkbox>
		</tr>
		<tr>
			<td></td>
			<td></td>
			<td><html:submit styleClass="button">Save</html:submit></td>
			<td></td>
		</tr>		
	</table>
</html:form>

<c:choose>
	<c:when test="${user != null}">
		<h2>Submitted Events</h2>
		<c:forEach var="event" items="${user.submittedEvents}">
			<c:choose>
				<c:when test="${event.conID == conID }">
					${event.eventName } -- <c:choose><c:when test="${event.status == 1 }">Submitted </c:when><c:when test="${event.status == 2 }">In Review</c:when><c:when test="${event.status == 3 }">Approved (${event.slotName})</c:when><c:when test="${event.status == 4 }">Rejected</c:when></c:choose><br>
				</c:when>
			</c:choose>
		</c:forEach>
		<h2>Events Registered</h2>
		<c:forEach var="reg" items="${user.registrations}">
			<c:choose>
				<c:when test="${reg.conID == conID }">
					<c:forEach var="event" items="${reg.events }">
						${event.event.eventName } -- ${event.event.slotName }<br>
					</c:forEach>
				</c:when>
			</c:choose>
		</c:forEach>
	</c:when>
</c:choose>
